package com.glw.sso.platform.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.glw.sso.platform.common.base.BaseEntity;
import com.glw.sso.platform.common.exception.ParamValidException;
import com.glw.sso.platform.common.group.Insert;
import com.glw.sso.platform.common.group.Update;
import com.glw.sso.platform.common.interfaces.Verifiable;
import com.glw.sso.platform.domain.enums.GenderEnum;
import com.glw.sso.platform.domain.enums.UserStateEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;

/**
 * <p>
 * 系统用户表
 * </p>
 *
 * @author AutoGenerator
 * @since 2021-11-14
 */
@Getter
@Setter
@TableName("system_user")
@ApiModel(value = "User对象", description = "用户表")
public class User extends BaseEntity implements Verifiable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("主键")
    @TableId(value = "id", type = IdType.AUTO)
    @NotEmpty(groups = Update.class, message = "id不能为空")
    private Long id;

    @ApiModelProperty(value = "用户唯一标识", hidden = true)
    private String pin;

    @ApiModelProperty("用户名")
    @NotEmpty(message = "30001#用户名不能为空")
    @Length(min = 6, max = 32, message = "用户名必须大于6位并且小于32位")
    private String username;

    @ApiModelProperty("密码(加密存储)")
    @NotEmpty(message = "密码不能为空")
    @Length(min = 6, max = 32, message = "密码必须大于6位并且小于32位")
    private String password;

    @ApiModelProperty("公司编号")
    @NotEmpty(message = "公司编号不能为空")
    private String companyId;

    @ApiModelProperty("员工工号")
    @NotEmpty(message = "员工编号不能为空")
    private Integer empCode;

    @ApiModelProperty("姓名")
    @NotEmpty(message = "姓名不能为空")
    private String name;

    @ApiModelProperty("手机号")
    @NotEmpty(message = "手机号不能为空")
    private String mobile;

    @ApiModelProperty("电话")
    private String telephone;

    @ApiModelProperty("身份证号")
    private String identificationCard;

    @ApiModelProperty("性别")
    private GenderEnum gender;

    @ApiModelProperty("邮箱")
    private String email;

    @ApiModelProperty("地址")
    private String address;

    @ApiModelProperty("头像缩略图地址")
    private String avatar;

    @ApiModelProperty("用户状态")
    private UserStateEnum state;

    @ApiModelProperty("备注")
    private String remark;

    @Override
    public void verifyInput() {
        // 一些复杂的校验可以放到这里
        if ("admin".equals(username)) {
            throw ParamValidException.create(ParamValidException.Code.PARAM_VALID_FAIL);
        }

    }
}
